#!/usr/bin/env python

import ConfigParser
import string
import os
import sys

import web
from web import form
import config
import access
import utils

render = web.template.render('templates/', cache=config.template_cache)

class index:
    def GET(self):
        lang_file = "from language." + access.get_lang() + ".admin import words"
        exec lang_file
        user = access.get_user()
        if not user:
            web.redirect('/login')

        print render.admin(words)

class top:
    def GET(self):
        lang_file = "from language." + access.get_lang() + ".admin import top_words"
        exec lang_file
        user = access.get_user()
        if not user:
            web.redirect('/login')

        print render.top(top_words)

class menu:
    def GET(self):
        lang_file = "from language." + access.get_lang() + ".admin import menu_words"
        exec lang_file
        user = access.get_user()
        if not user:
            web.redirect('/login')

        print render.menu(menu_words)

class main:
    def GET(self):
        lang_file = "from language." + access.get_lang() + ".admin import main_words"
        exec lang_file
        user = access.get_user()
        if not user:
            web.redirect('/login')

        print render.main(main_words)

class omsm_info:
    def GET(self):
        omsm_info = {}
        data = web.input()

        lang_file = "from language." + access.get_lang() + ".admin import omsm_info_words"
        exec lang_file
        user = access.get_user()
        if not user:
            web.redirect('/login')

        type = int(utils.filter_auth(data.type))
        omsm_info["type_value"] = type
        if(type == 1):
            cf = ConfigParser.ConfigParser()
            cf.read(os.getcwd() + '/' + config.global_config_file["omsm_info_file"])
            omsm_info["software_version"] = cf.get("omsm_info", "software_version")
            omsm_info["hardware_version"] = cf.get("omsm_info", "hardware_version")
        elif(type == 2):
            cf = open(config.global_config_file["lan_if_file"])
            lan_info = cf.readline().split()
            omsm_info["lan_ip"] = lan_info[1]
            omsm_info["lan_mask"] = lan_info[2]

        # get lan status
        print render.omsm_info(omsm_info_words, omsm_info)
